<?php
/*
 用户管理
 */
	namespace Admin\Controller;
	use Think\Controller;
	class UserController extends Controller {

		//首页
		public function index()
		{
    //查询       
         if ($_GET['sub']=="查询") {
                    $key=$_GET['keywords'];
            $wheres['username']=array('like',"%$key%");
            // $wheres['typeid']=$type;
            $wheres=array_filter($wheres); 
         }else{
            $wheres='';
         }


		$db=M("User"); // 实例化Plan对象
		$count      = $db->where($wheres)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(15)
		$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$Uarr = $db->where($wheres)->order('createtime DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('Uarr',$Uarr);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出
		$this->display(); // 输出模板
    }


		//用户详情
		public function userinfo()
		{ 	 
			$uid=I("get.id");
			$Uarr=M("User")->where('id='.$uid)->find();
			$this->Uarr=$Uarr;   
			//活动保单
			$Hbao=M("Hbaodan");
			 $Harr=$Hbao->field("hname")->where('uid='.$uid)->select();
				$this->Harr=$Harr; 
			 // 互保单  
			$Bao=M("Baodan");
			 $Barr=$Bao->field("jname")->where('uid='.$uid)->select();
			$this->Barr=$Barr;
			//钱包
			$Qian=M("Qianbao");
			$Qarr=$Qian->where('uid='.$uid)->find();
			$this->Qarr=$Qarr;
			//会员级别
			$Vip=M("Vip");
			$Varr=$Vip->where('uid='.$uid)->find(); 
			$this->Varr=$Varr; 

				if (!empty($Varr)) {

    			$sumtime=strtotime($Varr['endtime'])-strtotime($Varr['starttime']);
    			$perlnian=24*3600*365;
    			$jie=$sumtime/$perlnian;
    			$this->jie=$jie;

		
			}	
				//邀请收益

    			$yao=M("Yaoqing");
			    $count=$yao->field("jine")->where('yid=83')->select();
			    $newarr = array();
			    foreach ($count as $v) {
			    	
			    	array_push($newarr,$v['jine']);
 
			    	   
			    }
			  $sum=array_sum($newarr);
			       $this->sum=$sum;

			$this->display();
		}
		//交易记录
		public function userjilu()
		{
			$uid=I("get.user");
			$J=M("Jilu");
			$Jarr=$J->where("uid=".$uid)->select();      
			$this->Jarr=$Jarr;
			$this->display();
		}
		//提现操作
		public function xian()
		{   

	    //查询       
         if ($_GET['sub']=="查询") {
            $key=$_GET['keywords'];
            $wheres['dan']=array('like',"%$key%");
            $wheres=array_filter($wheres); 
         }else{
            $wheres='';
         }
		$db=M("Tixian"); // 实例化Plan对象
		$count      = $db->where($wheres)->count();// 查询满足要求的总记录数
		$Page       = new \Think\Page($count,15);// 实例化分页类 传入总记录数和每页显示的记录数(15)
		$show       = $Page->show();// 分页显示输出// 进行分页数据查询 注意limit方法的参数要使用Page类的属性
		$Uarr = $db->where($wheres)->order('createtime DESC')->limit($Page->firstRow.','.$Page->listRows)->select();
		$this->assign('Tarr',$Uarr);// 赋值数据集
		$this->assign('page',$show);// 赋值分页输出	   
		$this->display(); // 输出模板
		}
		public function upd()
		{
			$wheres['mid']=I("post.sid");
			$data['mstatus']=I("post.sta");
			if (IS_POST) {
				$db=M("Tixian"); 
				$list=$db->where($wheres)->save($data);
				if ($list) {
					echo "修改成功";
				}else{
					echo "修改失败";
				}
			}
			 
   
			   
		}
	}